/**
 * SerialCommunication.h
 *
 * @author Bematech S.A.
 */

#ifndef __BILBAO_PROTOCOL_SERIAL_SERIAL_COMMUNICATION_CLASS_H__
#define __BILBAO_PROTOCOL_SERIAL_SERIAL_COMMUNICATION_CLASS_H__

#include "bilbao/types.h"
#include "bilbao/util/SerialPort.h"
#include "bilbao/protocol/serial/Read.h"
#include "bilbao/protocol/serial/Write.h"
#include "bilbao/protocol/serial/SerialCommunicationManager.h"
#include "bilbao/protocol/serial/SincronyzedQueue.h"
#include "bilbao/util/Tokenizer.h"
#include "bilbao/led/LedController.h"

namespace bilbao
{
	namespace protocol
	{
		namespace serial
		{
			class SerialCommunicationManager;

			/**
			 *
			 */
			class SerialCommunication
			{

			friend class SerialCommunicationManager;

			public:

				/**
				 *
				 */
				static SerialCommunication* getInstance( util::SerialPort* serialPort );

				/**
				 * Método executar
				 */
				void read( Vector<String>& );

				/**
				 * Método enviar
				 */
				void send( const String& );

				/**
				 * Destrutor
				 */
				~SerialCommunication( void );

			protected:

				/**
				 *
				 */
				static SerialCommunication* _instance;

				/**
				 *
				 */
				static SerialCommunicationManager* _manager;

				/**
				 *
				 */
				util::SerialPort* _serialPort;

				/**
				 *
				 */
				Read _read;

				/**
				 *
				 */
				Write _write;

				/*
				 *
				 */
				SincronyzedQueue _filaComandos;

				/*
				 *
				 */
				SincronyzedQueue _filaRespostas;

				/**
				 * Construtor Padrão
				 */
				SerialCommunication( void );

				/**
				 * Construtor
				 */
				SerialCommunication( util::SerialPort* serialPort );

			}; // class Communication
		} //namespace serial
	} // namespace protocol
} // namespace bilbao


#endif //__BILBAO_PROTOCOL_SERIAL_SERIAL_COMMUNICATION_CLASS_H__
